package fr.bda.cloud.tray;

import java.util.ArrayList;
import java.util.List;

public abstract class CloudTrayDialogController {

	protected List<CloudTrayDialogDataValidator> validators = new ArrayList<>();
	protected final CloudTray cloudTray;

	public CloudTrayDialogController(CloudTray cloudTray) {
		this.cloudTray = cloudTray;
	}

	public abstract <C extends CloudTrayDialogController> void initDialog(CloudTrayDialog<C> dialog);

	public <C extends CloudTrayDialogController> boolean checkDialogData(CloudTrayDialog<C> dialog) {
		for (CloudTrayDialogDataValidator validator : validators) {
			if (!validator.validate(dialog)) {
				return false;
			}
		}
		return true;
	}

	public abstract <C extends CloudTrayDialogController> void saveDialogData(CloudTrayDialog<C> dialog);
}
